package zhang.test.sqlitedemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import zhang.test.sqlitedemo.data.LocalDataSource;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.add)
    Button add;
    @BindView(R.id.upadate)
    Button upadate;
    @BindView(R.id.delete)
    Button delete;
    @BindView(R.id.query)
    Button query;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.add, R.id.delete, R.id.upadate, R.id.query})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add:
                Toast.makeText(this, "add", Toast.LENGTH_SHORT).show();
                LocalDataSource.getInstance(this).add();
                break;

            case R.id.upadate:
                Toast.makeText(this, "update", Toast.LENGTH_SHORT).show();
                LocalDataSource.getInstance(this).update();
                break;

            case R.id.delete:
                Toast.makeText(this, "delete", Toast.LENGTH_SHORT).show();
                LocalDataSource.getInstance(this).delete();
                break;

            case R.id.query:
                Toast.makeText(this, "query", Toast.LENGTH_SHORT).show();
                LocalDataSource.getInstance(this).find();
                for (int i = 0; i < 5; i++) {
                    LocalDataSource.getInstance(this).find();
                }
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.bind(this).unbind();
    }
}
